using System;
using System.Collections.Generic;
using System.Text;

namespace BlogClient.BlogData
{
    public partial class BlogData : System.Data.DataSet
    {
        public partial class LivePostsDataTable : System.Data.DataTable
        {
            private const int MAX_UQ_LOOP = 100;

            public bool GenerateNewPost()
            {
                bool uniqueNameFound = false;
                string newPostName = "";
                int counter = 1;

                while (uniqueNameFound == false && counter <= MAX_UQ_LOOP)
                {
                    newPostName = "New Post " + counter.ToString();

                    if (this.Select("Title = '" + newPostName + "'").Length == 0)
                    {
                        uniqueNameFound = true;
                    }
                    else
                    {
                        counter++;
                    }
                }

                if (counter > MAX_UQ_LOOP)
                {
                    return false;
                }

                BlogClient.BlogData.BlogData.LivePostsRow post = (BlogClient.BlogData.BlogData.LivePostsRow)this.NewRow();
                post.OriginalCreationDate = DateTime.Now;
                post.UpdateDate = DateTime.Now;
                post.Title = newPostName;
                post.Html = "";
                this.Rows.Add(post);

                return true;
            }
            /*
             * 
                    MessageBox.Show(
                        @"You have too many posts named ""New Post"", please remove one of them before adding a new post",
                        "Post Not Created",
                        MessageBoxButtons.OK);*/
        }
    }
}
